package com.survey.Controller;

import com.survey.pojo.data.LinkDO;
import com.survey.pojo.data.SurveyDO;
import com.survey.pojo.data.UserDO;
import com.survey.service.LinkService;
import com.survey.service.SurveyService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;

@Controller
public class IndexController {

    @Autowired
    SurveyService surveyService;
    @Autowired
    LinkService linkService;
    @RequestMapping("index")
    public String index(HttpSession session, Model model, HttpServletResponse response) throws Exception {
        UserDO userDO= (UserDO) session.getAttribute("user");
        List<SurveyDO> surveyDOS = surveyService.listSurvey();
        List<LinkDO> linkDOS = linkService.listLink();
        List<SurveyDO> hotsurvey= surveyService.listhotsurvey();

        model.addAttribute("link",linkDOS);
        model.addAttribute("user",userDO);
        model.addAttribute("survey",surveyDOS);
        model.addAttribute("hotsurvey",hotsurvey);
        return "index.jsp";
    }
}
